package com.okami.clazz.stack;

/**
 * @author: TanJingyu
 * @create: 2021-03-09 15:13
 **/
public class CoderkStack<T> {
    private static class Node<V> {
        private V item;
        private Node<V> next;

        Node(){
            this.item = null;
            this.next = null;
        }

        Node(V item, Node<V> next) {
            this.item = item;
            this.next = next;
        }

        Boolean end() {
            return item == null && next == null;
        }

    }

    private Node<T> top = new Node<>();

    public T push(T t) {
        top = new Node<>(t, top);
        return t;
    }

    public T pop() {
        T item = top.item;
        if (!top.end()) {
            top = top.next;
        }
        return item;
    }
}
